<!DOCTYPE html>
<html lang="zh">

	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<title>商品详情</title>
		<link rel="stylesheet" type="text/css" href="css/index.css" />
		<link rel="stylesheet" type="text/css" href="css/weui.min.css" />
		<link rel="stylesheet" type="text/css" href="css/jquery-weui.min.css" />
		<link rel="stylesheet" href="css/ydui.css" />
<link rel="stylesheet" href="css/demo.css" />
	</head>

	<body>
		<div class="shopdetail">
			<div class="schooltop">
				<div class="schooltp">
					<div class="schooltp1">
						<div class="sctp1fl">
							<div class="splogin">
								
							</div>
						</div>
						<div class="sctp1fr">
							<div class="shopcart">
								<a class="nerr" href="shopcart.html" target="_blank">
								<img src="img/shopcrat.png" alt="" class="gwcimg" />
								<span class="gwctxt">我的购物车</span>
								</a>
							</div>
						</div>
					</div>
					<!--<div class="schooltp2">
						<p class="schoolmc">阿克苏地区库车中等职业技术学校--欢迎您</p>
					</div>-->
				</div>
				
			</div>
			<div id='content' class="shopdlCon">
				<div class="shopxqfl">
					<img id='img' src="" alt="" class="shopxqimg" />
				</div>
				<div class="shopxqfr">
					<div id='title' class="shopname"></div>
					<p class="shopprice xqpeice"><span style="color: #333;margin-right: 10px;">商品价格</span><span>￥</span><span class="jiage" id='price'></span></p>
					<div class="address">
						<!--<div class="weui-cell" style="padding: 0;margin-bottom: 15px;">
							<div class="weui-cell__hd" style="width: 64px;margin-right: 10px;"><label for="name" class="weui-label">配送至</label></div>
							<div class="weui-cell__bd">
								<input class="weui-input" id="start" type="text" value="新疆维吾尔自治区  阿克苏地区  库车县">
							</div>
						</div>-->
						<div class="m-cell">
							<div class="cell-item" style="padding-left: 0;">
								<div  style="width: 64px;margin-right: 10px;font: 16px/30px '微软雅黑';">配送至</div>
								<div class="cell-right cell-arrow">
									<input type="text"  class="cell-input" style="font: 14px/30px '微软雅黑';" readonly id="J_Address2" value="新疆 乌鲁木齐市 天山区" placeholder="请选择收货地址">
								</div>
							</div>
						</div>						
					</div>
					<div class="selectlb">
						<div class="seletxt">选择规格</div>
						<div id='norm' class="splbie">
						</div>
					</div>
					<div class="jishuqi" style="white-space: nowrap;">
						<div class="weui-cell" style="padding: 0;">
							<div class="weui-cell__bd" style="width: 64px;flex: unset;margin-right: 10px;">
								<p style="width: 50px;">选择数量</p>
							</div>
							<div class="weui-cell__ft">
								<div class="weui-count">
									<a class="weui-count__btn weui-count__decrease"></a>
									<input id="selectCount" class="weui-count__number" type="number" value="1" />
									<a class="weui-count__btn weui-count__increase"></a>
								</div>
							</div>
						</div>
					</div>
					<div class="gouwuc" onclick="addCar()">加入购物车</div>

				</div>
			</div>
			<div class="shopbottom">
				<div class="shopbmcon">
					<p class="schoolname"><a href="http://www.worlduc.com/e/default.aspx?eid=2784009" target="_blank">阿克苏地区库车中等职业技术学校</a></p>
					<p class="schoolname">学校地址：阿克苏地区库车县福鸿路26号</p>
				</div>
			</div>
		</div>
	</body>

</html>
<script src="js/jquery.min.js"></script>
<script src="js/jquery-weui.min.js"></script>
<script type="text/javascript" src="js/city-picker.js"></script>

<script>
	$("#start").cityPicker({
		title: "选择出发地",
		onChange: function(picker, values, displayValues) {
			console.log(values, displayValues);
		}
	});
	var MAX = 99,
		MIN = 1;
	$('.weui-count__decrease').click(function(e) {
		var $input = $(e.currentTarget).parent().find('.weui-count__number');
		var number = parseInt($input.val() || "0") - 1
		if(number < MIN) number = MIN;
		$input.val(number)
	})
	$('.weui-count__increase').click(function(e) {
		var $input = $(e.currentTarget).parent().find('.weui-count__number');
		var number = parseInt($input.val() || "0") + 1
		if(number > MAX) number = MAX;
		$input.val(number)
	});
	</script>
	<script type="text/javascript" src="js/Global.js" ></script>
<script type="text/javascript" src="js/jquery-1.11.0.js" ></script>
<script src="js/ydui.citys.js"></script>
<script src="js/ydui.js"></script>
<script src="js/ydui.flexible.js"></script>
	<script>
		var globalGood=null;
		var globalNorms = null;
	jQuery(document).ready(function() {
		getUser();
		getgood();
		$(".select1").click(function(){
			$(this).addClass("shopactive").siblings().removeClass("shopactive")
			console.log('nihao')
		})
	});
//	function getUser(){
//		$.ajax({
//			type: "get",
//			url: requesturl + "user/user",
//			async: false,
//			xhrFields: {
//				withCredentials: true
//			},
//			success: function(data) {
//				if(data.status == "success") {
//					$('#username').html(data.data.phone+'，欢迎您！');
//					$('#logina').hide();
//					$('#registera').hide();
//				} else {
//					$('#username').hide();
//				}
//			},
//			error: function(data) {
//				alert("网络原因发送失败：" + data.responseText);
//			}
//		});
//	}
	/*获得商品*/
	function getgood(){
		var goodid = getQueryVariable("id");
		$.ajax({
			type: "get",
			url: requesturl + "goods/detail",
			async: false,
			data:{
				"goodid":goodid
			},
			xhrFields: {
				withCredentials: true
			},
			success: function(data) {
				if(data.status == "success") {
					loadDetail(data.data);
				} else {
					window.location.href = './servererror.html';
				}
			},
			error: function(data) {
				alert("网络原因发送失败：" + data.responseText);
			}
		});
		
	}
	function loadDetail(good){
		globalGood = good;
		var src ='./goodsimg/'+good.img;
		$("#img").attr('src',src);
		$('#norm').append(getNorm(good.id));
		$('#title').append(good.content);
		$('#price').append(good.price);
	}
	//获取规格
	function getNorm(id){
		var norms = new Array();
		$.ajax({
			type: "get",
			url: requesturl +'producttype/productnorm' ,
			async: false,
			data:{
				'goodsid':id
			},
			xhrFields: {
				withCredentials: true
			},
			success: function(data) {
				if(data.status == "success") {
					norms=data.data;
				} else{
					
				}
			},
			error: function(data) {
				window.location.href = './servererror.html';
			}
		});
		var total =""
		var head = ' <p class="select1">'
		for (var i = 0; i < norms.length; i++) {
			var norm = norms[i];
			total = total+head+norm.typedesc+'</p> ';
		}
		globalNorms = norms;
		return total;	
		
	}
	function addCar(){
		var goodid =globalGood.id ;
		var count =$('#selectCount').val();	
		//选择了那些尺寸。
		var sizesq = getSelectSize();
		
		$.ajax({
			type: "post",
			url: requesturl +'shopcar/add' ,
			async: false,
			data:{
				'goodsid':globalGood.id,
				'count':$('#selectCount').val(),
				'price':globalGood.price,
				'sizesq':sizesq
			},
			xhrFields: {
				withCredentials: true
			},
			success: function(data) {
				if(data.status == "success") {
					alert("加入成功！");
				} else{
					window.location.href="./login.html";
				}
			},
			error: function(data) {
				window.location.href = './servererror.html';
			}
		});
	}
	function selectNorm(){
		$.ajax({
			type: "get",
			url: requesturl +'producttype/productnorm' ,
			async: false,
			data:{
				'goodsid':id
			},
			xhrFields: {
				withCredentials: true
			},
			success: function(data) {
				if(data.status == "success") {
					norms=data.data;
				} else{
					
				}
			},
			error: function(data) {
				window.location.href = './servererror.html';
			}
		});
		
	}
	function getSelectSize(){
		return "3_4";
	}
	
</script>
<script>
	! function() {
				var $target = $('#J_Address2');

				$target.citySelect({
					provance: '新疆',
					city: '乌鲁木齐市',
					area: '天山区'
				});

				$target.on('click', function(event) {
					event.stopPropagation();
					$target.citySelect('open');
				});

				$target.on('done.ydui.cityselect', function(ret) {
					$(this).val(ret.provance + ' ' + ret.city + ' ' + ret.area);
				});
			}();

</script>
<script type="text/javascript" src="js/loginstate.js" ></script>